package cn.iocoder.yudao.module.blog.controller.app.poster;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.blog.controller.admin.poster.vo.PosterPageReqVO;
import cn.iocoder.yudao.module.blog.controller.admin.poster.vo.PosterRespVO;
import cn.iocoder.yudao.module.blog.controller.admin.postertype.vo.PosterTypeRespVO;
import cn.iocoder.yudao.module.blog.convert.poster.PosterConvert;
import cn.iocoder.yudao.module.blog.convert.postertype.PosterTypeConvert;
import cn.iocoder.yudao.module.blog.dal.dataobject.poster.PosterDO;
import cn.iocoder.yudao.module.blog.dal.dataobject.postertype.PosterTypeDO;
import cn.iocoder.yudao.module.blog.service.poster.PosterService;
import cn.iocoder.yudao.module.blog.service.postertype.PosterTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 海报")
@RestController
@RequestMapping("/blog/poster")
@Validated
@Slf4j
public class AppPosterController {

    @Resource
    private PosterService posterService;

    @Resource
    private PosterTypeService posterTypeService;

    @GetMapping("/page")
    @Operation(summary = "获得海报分页")
    public CommonResult<PageResult<PosterRespVO>> getPosterPage(@Valid PosterPageReqVO pageVO) {
        PageResult<PosterDO> pageResult = posterService.getPosterPage(pageVO);
        return success(PosterConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/types")
    @Operation(summary = "获得所有海报类型")
    public CommonResult<List<PosterTypeRespVO>> getAllPoster(){
        List<PosterTypeDO> list = posterTypeService.getAll();

        return success(PosterTypeConvert.INSTANCE.convertList(list));
    }
}
